package com.wzy.未封装Jdbc;

import java.sql.*;
import java.util.Dictionary;

public class Jdbc {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //使用JDBC连接数据
        //1、导包  MySQL 驱动包

        //2、创建 驱动管理对象
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/newsdb";
        String user = "root";
        String pass = "wzy123518";
        Connection connection = DriverManager.getConnection(url, user, pass);

        //3、创建SQL执行器
        Statement statement = connection.createStatement();
        //4、调用sql执行器里查询的方法
        String sql = "SELECT * FROM `news_detail`";
        ResultSet res = statement.executeQuery(sql);

        //5、遍历输出sql执行器返回查询数据的结果集
        while(res.next()){
            int id = res.getInt(1);
            String title = res.getString(3);
            System.out.println("id:"+id+"======标题："+title);
        }

        //6、关闭连接
        res.close();
        statement.close();
        connection.close();

        //驱动管理器
    }
}
